<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>JSONP实现跨域2</title>
</head>

<body>
    <div id="mydiv">
        <button id="btn">点击</button>
    </div>
</body>
<script type="text/javascript">
    function handleResponse(response) {
        console.log(response);
        console.log(handleResponse);
    }
</script>
<script type="text/javascript">
    window.onload = function() {

        var oBtn = document.getElementById('btn');

        oBtn.onclick = function() {

            var script = document.createElement("script");
            script.src = "https://api.douban.com/v2/book/search?q=javascript&count=1&callback=handleResponse";
            document.body.insertBefore(script, document.body.firstChild);
        };
    };
</script>

</html>